<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			//筛选数组元素
			function selectArr(arr, symbol, value) {
				// arr:array[] symbol:String value:double -> result:array[] 
				result = []
				for (var i = 0; i <= arr.length - 1; i++) {
					switch (symbol) {

						case "=":
							if (arr[i] == value) {
								result.push(arr[i]);
							}
							break;

						case ">=":
							if (arr[i] >= value) {
								result.push(arr[i]);
							}
							break;

						case ">":
							if (arr[i] > value) {
								result.push(arr[i]);
							}
							break;

						case "<=":
							if (arr[i] <= value) {
								result.push(arr[i]);
							}
							break;

						case "<":
							if (arr[i] < value) {
								result.push(arr[i]);
							}
							break;
					}
				}
				return result;
			}
			var arr = [1, 4, 3, 2, 5, 5];
			//筛选等于3的元素
			console.log(selectArr(arr, "=", 3));
			//筛选大于等于3的元素
			console.log(selectArr(arr, ">=", 3));
			//筛选大于三的元素
			console.log(selectArr(arr, ">", 3));
			//筛选小于等于3的元素
			console.log(selectArr(arr, "<=", 3));
			//筛选小于3的元素
			console.log(selectArr(arr, "<", 3));

			//翻转数组
			function overturnArr(arr) {
				//arr:array[] -> arr:array[]
				for (var i = 0; i <= Math.ceil(arr.length / 2) - 1; i++) {
					var temp;
					temp = arr[i];
					arr[i] = arr[arr.length - 1 - i];
					arr[arr.length - 1 - i] = temp;
				}
				return arr;
			}
			//翻转数组数组结果
			console.log(overturnArr(arr));

			//数组求和
			function returnArrSum(arr) {
				//arr:array[] -> sum:double
				var sum = 0;
				for (var i = 0; i <= arr.length - 1; i++) {
					sum += arr[i];
				}
				return sum;
			}
			console.log("数组求和: " + returnArrSum(arr));

			//数组求最大值
			function returnMaxValue(arr) {
				//arr:array[] -> result:double
				var result = 0;
				for (var i = 0; i <= arr.length - 1; i++) {
					if (result < arr[i]) {
						result = arr[i];
					}
				}
				return result;
			}
			console.log("数组求最大值: " + returnMaxValue(arr));

			//冒泡排序
			function mySort(arr) {
				//arr:array[] -> arr:array[]
				for (var i = 1; i <= arr.length - 1; i++) {
					for (var j = 0; j <= arr.length - i; j++) {
						if (arr[j] > arr[j + 1]) {
							var temp;
							temp = arr[j];
							arr[j] = arr[j + 1];
							arr[j + 1] = temp;
						}
					}
				}
				return arr;
			}
			console.log("冒泡排序结果: " + mySort(arr));

			//数组去重
			function deleRepeatArr(arr) {
				//arr:array[] -> arr:array[]
				var myset = new Set(arr);
				arr = [];
				for (var i of myset) {
					arr.push(i);
				}
				return arr;
			}
			console.log("数组去重结果: " + deleRepeatArr(arr));
		</script>
	</head>
	<body>
	</body>
</html>
